package com.googlecode.gwtCorsForIe8.client;

import com.google.gwt.core.client.JavaScriptObject;

/**
 * Original from
 * http://experienceswithgwt.blogspot.com/2010/04/gwt-and-cross-site
 * -requests_28.html
 * 
 * @author Sebastian
 */
public class XDomainRequest extends JavaScriptObject {
	public static native XDomainRequest create() /*-{
		if ($wnd.XDomainRequest) {
		return new XDomainRequest();
		}
		else {
		$wnd.alert("Cross site requests not supported in this browser");
		return null;
		}
	}-*/;
protected XDomainRequest() {}
public final native void abort() /*-{
	this.abort();
}-*/;
public final native void clear() /*-{
	var self = this;
	$wnd.setTimeout(function() {
	self.onload= new Function();
	self.onprogress= new Function();
	self.onerror= new Function();
	self.ontimeout= new Function();
	}, 0);
}-*/;
public final native String getContentType() /*-{
	return this.contentType;
}-*/;
public final native void setTimeout(int value) /*-{
	this.tmeout=value;
}-*/;
public final native int getTimeout() /*-{
	return this.timeout;
}-*/;
public final native String getResponseText() /*-{
	return this.responseText;
}-*/;
public final native void open(String httpMethod, String url) /*-{
	this.open(httpMethod, url);
}-*/;
public final native void send(String requestData) /*-{
	this.send(requestData);
}-*/;
public final native void setHandler(XDomainRequestHandler handler) /*-{
	var _this = this;
	this.onload = $entry(function() {
	handler.@com.googlecode.gwtCorsForIe8.client.XDomainRequestHandler::onLoad(Lcom/googlecode/gwtCorsForIe8/client/XDomainRequest;)(_this);
	});
	this.onerror = $entry(function() {
	handler.@com.googlecode.gwtCorsForIe8.client.XDomainRequestHandler::onLoad(Lcom/googlecode/gwtCorsForIe8/client/XDomainRequest;)(_this);
	});
	this.ontimeout = $entry(function() {
	handler.@com.googlecode.gwtCorsForIe8.client.XDomainRequestHandler::onTimeout(Lcom/googlecode/gwtCorsForIe8/client/XDomainRequest;)(_this);
	});
	this.onprogress = $entry(function() {
	handler.@com.googlecode.gwtCorsForIe8.client.XDomainRequestHandler::onProgress(Lcom/googlecode/gwtCorsForIe8/client/XDomainRequest;)(_this);
	});
}-*/;
}